<template>
  <div>
    <!-- 无children -->
    <el-menu-item
      :index="item.path"
      v-for="item in noChildren"
      :key="item.menuId"
      @click="clickMenu(item)"
    >
      <i :class="'iconfont icon-zhankai1'"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <!-- 有children -->
    <template v-if="isCollapse">
      <el-submenu
        :index="index + '' + itemA.label"
        v-for="(itemA, index) in hasChildren"
        :key="itemA.menuId"
      >
        <template slot="title">
          <i :class="'iconfont icon-zhankai1'"></i>
          <span slot="title">{{ itemA.label }}</span>
        </template>
        <el-menu-item-group>
    
          <ForMenu :menu="itemA.children"></ForMenu>
        </el-menu-item-group>
      </el-submenu>
    </template>
    <template v-else>
      <HoverMenu :menu="hasChildren"></HoverMenu>
    </template>
  </div>
</template>

<script>
export default {
  name: "ForMenu",
  props: ["menu"],
  data() {
    return {};
  },
  computed: {
    noChildren() {
      return this.menu.filter(item => !item.children);
    },
    hasChildren() {
      return this.menu.filter(item => item.children);
    },
    isCollapse() {
      return this.$store.state.tab.isCollapse;
    }
  },
  methods: {
    clickMenu(item) {
      // 设置路由跳转
      // this.$router.push({ name: item.name })
      console.log(item,'item')
      this.$store.commit("selectMenu", item);
    }
  }
};
</script>

<style lang="scss" scoped>
// 下拉小三角，改为右侧
.el-submenu /deep/.el-icon-arrow-down:before {
  content: "\e6e0" !important;
}
// 展开小三角，改为下側
.el-submenu.is-opened /deep/.el-icon-arrow-down:before {
  content: "\e6e1" !important;
}
.el-menu-item.is-active > span {
  position: relative;
}
// 点击某个菜单item激活后样式
.el-menu-item.is-active > span::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  position: absolute;
  top: 8px;
  left: -15px;
  border-radius: 50%;
  background-color: #ea8a5e;
}

// 二三级菜单选中激活样式
/deep/.el-submenu.is-active > .el-submenu__title {
  // background: #26324B!important; // 二级的菜单组
  border-right: 0px solid #000 !important;
}
// 二三级item激活背景
.el-menu-item.is-active {
  background: #26324b !important;
}
// 
/deep/.el-menu--collapse>.el-menu-item span, /deep/.el-menu--collapse>.el-submenu>.el-submenu__title span {
    overflow: hidden;
    visibility:visible; 
    display: inline-block;
    height: auto;
    width: auto;
}
</style>